<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>

<body>
<form action="/login" method="post">
    <label for="userN">用户名：</label>
    <input id="userN" name="username"/>
    <label for="pwd">密码：</label>
    <input id="pwd" name="password"/>
    <button type="submit">登录</button>
</form>
<script></script>
<div class="form">
    <label for="username">用户名：</label>
    <input id="username"/>
    <label for="password">密码：</label>
    <input id="password"/>
    <button onclick="go()">登录</button>
</div>
<script>
    function go() {
        let username = document.getElementById("username").value;
        let password = document.getElementById("password").value
        console.log(username, password);
        axios({
            method: "post",
            url: "/login",
            data: "username=" + username + "&password=" + password;
        }).then((res) => {
            console.log(res.data)
        })
        // let request = new XMLHttpRequest();
        // request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        // request.onreadystatechange = function () {
        //     if (request.readyState == 4 && request.status == 200) {
        //         console.log(request.responseText)
        //     } else {
        //         console.log(request.responseText)
        //     }
        // }
        // request.open("POST", "/login?" + "username=" + username + "&password=" + password);
        // request.send();
        // console.log(request)
    }
</script>
</body>
</html>